// 表单属性【右面板】
import { i18n } from "@/i18n";
import {
  advancedComponents,
  cascaderConfig,
  checkboxConfig,
  composeComponents,
  dateConfig,
  deptComponents,
  fileConfig,
  horizontalInputConfig,
  imageConfig,
  imageSelectConfig,
  inputConfig,
  matrixComponents,
  numberConfig,
  radioConfig,
  reseverComponents,
  selectConfig,
  textareaConfig
} from "./config";

export const examConf = {
  formRef: "elForm",
  formModel: "formData",
  size: "mini",
  labelPosition: "top",
  labelWidth: 100,
  formRules: "rules",
  gutter: 20,
  disabled: false,
  span: 24,
  title: i18n.global.t("formgen.config.examTile"),
  description: i18n.global.t("formgen.config.description"),
  formBtns: true,
  unFocusedComponentBorder: true
};

const drawImageConfig = {
  typeId: "SIGN_PAD",
  config: {
    label: i18n.global.t("formgen.config.DrawImage"),
    showLabel: true,
    defaultValue: undefined,
    showDefaultValue: false,
    showRequired: true,
    showClearable: false,
    showRegList: false,
    tag: "draw-image",
    tagIcon: "sign-pad",
    span: 24,
    required: true,
    regList: [],
    // 公式校验
    formulaValidate: [],
    changeTag: false
  },
  color: "#000000",
  style: { width: "100%" },
  action: "/form/file/upload/",
  backgroundImg: "",
  textConfig: {
    tips: i18n.global.t("formgen.drawImage.tips"),
    clearBtnText: i18n.global.t("formgen.sign.clear"),
    confirmBtnText: i18n.global.t("formI18n.all.confirm"),
    backBtnText: i18n.global.t("formgen.sign.withdraw"),
    reSignBtnText: i18n.global.t("formgen.drawImage.resignBtnText"),
    drawBtnText: i18n.global.t("formgen.drawImage.drawBtnText"),
    eraserBtnText: i18n.global.t("formgen.drawImage.eraserBtnText")
  }
};

// 基础组件 【基础组件】
export const examComponents = [
  inputConfig,
  numberConfig,
  textareaConfig,
  selectConfig,
  radioConfig,
  checkboxConfig,
  drawImageConfig,

  horizontalInputConfig
];

// 选择组件
export const selectComponents = [cascaderConfig, imageSelectConfig];

export const allComponents = [
  {
    title: i18n.global.t("formgen.config.examComponents"),
    list: examComponents
  },
  {
    title: i18n.global.t("formgen.config.selectComponents"),
    list: selectComponents
  },
  {
    title: i18n.global.t("formgen.config.advancedComponents"),
    list: [dateConfig, fileConfig, imageConfig, ...advancedComponents]
  },
  {
    title: i18n.global.t("formgen.config.reseverComponents"),
    list: reseverComponents
  },
  {
    title: i18n.global.t("formgen.config.matrixComponents"),
    list: matrixComponents
  },
  {
    title: i18n.global.t("formgen.config.composeComponents"),
    list: composeComponents
  },
  {
    title: i18n.global.t("formgen.config.deptComponents"),
    list: deptComponents
  }
];
interface ComponentsObj {
  [key: string]: any;
}

export let componentsObj: ComponentsObj = {};

export function getExamComponentsObj() {
  if (!componentsObj) {
    initComponentsObj();
  }
  return componentsObj;
}

export function initComponentsObj() {
  componentsObj = {};
  allComponents.forEach(comps => {
    comps.list.forEach(item => {
      if (!componentsObj[item.typeId]) {
        componentsObj[item.typeId] = item;
      }
    });
  });
}

export const examComIds: string[] = examComponents.map((item: any) => item.typeId as string);

export const selectFields: string[] = ["RADIO", "CHECKBOX", "IMG_SELECT", "SELECT"];
export const inputFields: string[] = ["INPUT", "TEXTAREA", "NUMBER"];

export default { allComponents };
